<?php
/**
 * Created by PhpStorm.
 * User: changyifan
 * Date: 2018/3/15
 * Time: 下午3:16
 */

namespace Home\Model;
use Think\Model\BaseDao;
use Think\Model\BaseModel;

class ProfessionModel extends BaseModel{

    protected $_link = array(
        'Teacher' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name' => 'Teacher',
            'foreign_key' => 'tea_id',
            'mapping_fields' => 'tea_name',
            'as_fields' => 'tea_name'
        ),
        'Department' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name' => 'Department',
            'foreign_key' => 'dept_id',
            'mapping_fields' => 'sch_id',
            'as_fields' => 'sch_id'
        ),
    );
    protected $_scope = array(
        'dataShow' => array(
            'where' => array('dept_id' => ''),
        ),
    );


    public function getProfessionInfoListByAll(){
        $info = $this->select();
        return $info ? $info : array();
    }


    public function getProfeesionInfoListWithTeacherName($dept_id){
        if ($dept_id == 0) {
            $dept_id = array('like', "%%");
        }
        $info = $this -> scope('dataShow',array('where'=>array('dept_id'=>$dept_id)))->relation(true) -> select();
        if($info){
            return $info;
        }else{
            return array();
        }
    }


}